package com.sq.partner.manager.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.properties.PropertyValueEncryptionUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
/**
* @File: ReadProperties.java 
* @Package com.ccic.util 
* @Description: 读取属性文件
* @author liyuan  
* @date Jan 11, 2013 11:11:09 AM 
* @version V1.0
 */
public class ReadProperties extends PropertyPlaceholderConfigurer{
	public static Map<String,Object> map=null;
	
	private StringEncryptor stringEncryptor;
	public StringEncryptor getStringEncryptor() {
		return stringEncryptor;
	}
	public void setStringEncryptor(StringEncryptor stringEncryptor) {
		this.stringEncryptor = stringEncryptor;
	}
		
	@Override
	protected String convertPropertyValue(final String originalValue) {
		if (originalValue == null) return null;
		    //采用Jasypt实现在配置文件中保存加密配置串，避免明文密码等泄露问题。
			if (PropertyValueEncryptionUtils.isEncryptedValue(originalValue)) {
				String newValue = PropertyValueEncryptionUtils.decrypt(originalValue,stringEncryptor);
				return newValue;
			}
		 
		return originalValue;
	}
	
	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,Properties props) throws BeansException {
		super.processProperties(beanFactoryToProcess, props);
		map = new HashMap<String,Object>();
        for (Object key : props.keySet()) { 
            String keyStr = key.toString(); 
            String value = props.getProperty(keyStr); 
            map.put(keyStr, value);
        }
	}
}